/**
*	@file    \A\1.cpp
*	@date    2013-10-6 17:15
*	@author  Il'yas Garipov <logirz728@gmail.com>
*
*	Primes filter-er.
*
*	@version 1.0.2
*
*	@par First, the amount of numbers to be submitted is inputted;
*	@par Following that, go those numbers themselves.
*	@par Outputted are the prime numbers from input sequence
*/

#include <stdio.h>
#include <math.h>
#include <assert.h>

#define MAX_N_ACCEPTABLE 10000 //!< defining instead of const to pierce the printf() textual output
#ifndef NDEBUG
	#define DOUT( toprint ) printf( "\n# " toprint )	//!< Debug output, prints a plain text line preceded by #
	#define DPUT( toput , x ) printf( "\n# " toput , x )//!< Debug put, a DOUT with a single variable inside
	#define DLN											//!< Debug line, doesn't exist in release (with NDEBUG defined)
	#define DPUTCLOSURE	DOUT("=============================================================================");\
						DPUT("FILE: %s", __FILE__ );\
						DPUT("COMPILATION DATE: %s", __DATE__ );\
						DPUT("COMPILATION TIME: %s", __TIME__ )//!< Put a closing statement, complete with datestamp and finename.
#else
	#define DOUT
	#define DPUT
	#define DLN if(0)
	#define DPUTCLOSURE
#endif

const long long int MAX_PRIME_CEILING 100000;	//!< The absolute maximum an intermediary prime can't overcome

int main()
{
	DOUT("=======================2007, 1 semester assignment, 1-A=======================");
	DOUT("==============================================================================");
	DOUT("Please enter the number of the numbers to be submitted to inspection:");
	DOUT(">");

	long long int n = 0;    //n is long long because that'll lead to more reliable asserts
	int chk = scanf("%lld", &n);
	DLN assert(("You have entered a single number" , chk == 1));
	DLN assert(("N is actually less than MAX_N_ACCEPTABLE" , (n < MAX_N_ACCEPTABLE)));

	DPUT("Enter those %lld numbers in question:", n);
	DOUT(">");

	long int nInput[MAX_N_ACCEPTABLE] = {0},
	                         maxelem = 1;

	for(int i = 0; i < n; i++) {
		chk = scanf("%ld", &nInput[i]);				//idk why, but it doesn't properly check
		DLN assert(("No garbage input", chk == 1));	//if there were precisely n numbers
													 //in input. However, it rejects letters
		if(nInput[i] > maxelem)
			maxelem = nInput[i];
	}

	bool bComp[MAX_PRIME_CEILING] = {0};			//if i-th of this is 1 then the i is composite

	for(long int j = 2; j < maxelem; j++) {

		if((!bComp[j]) && (j < (maxelem / 2))) {
			for(int k = 2*j; k <= maxelem; k += j)
				bComp[k] = 1;
		}

	}

	for(int i = 0; i < n; i++) {
		if(!(bComp[ nInput[i] ]))
			printf("%ld ", nInput[i]);
	}


	DPUTCLOSURE;
	return 0;
}

